/*******************************************************************************
 * Copyright (c) 2006 CEA List.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     CEA List - initial API and implementation
 *******************************************************************************/
package com.cea.papyrus.tabbedproperties.section;

import org.eclipse.gef.commands.Command;
import org.eclipse.gef.commands.CommandStack;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.CLabel;
import org.eclipse.swt.events.FocusEvent;
import org.eclipse.swt.events.KeyAdapter;
import org.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.views.properties.tabbed.ITabbedPropertyConstants;
import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetPage;
import org.eclipse.uml2.uml.ElementImport;
import org.eclipse.uml2.uml.ExtensionPoint;
import org.eclipse.uml2.uml.NamedElement;

import com.cea.papyrus.core.commands.factories.GenericCommandFactory;
import com.cea.papyrus.core.editor.MultiDiagramEditor;
import com.cea.papyrus.core.tabbedproperties.PropertyViewSection;
import com.cea.papyrus.umlutils.ExtensionPointUtil;

/**
 * Defines the extension point explanation section of extension points.
 */
public class ExtensionPointExplanationSection extends PropertyViewSection {

	/** The explanation text */
	private Text explanationText;

	/**
	 * {@inheritDoc}
	 */
	@Override
	public void createControls(Composite parent, TabbedPropertySheetPage tabbedPropertySheetPage) {
		super.createControls(parent, tabbedPropertySheetPage);
		
		Composite composite = getWidgetFactory().createFlatFormComposite(parent);
		FormData data;

		explanationText = getWidgetFactory().createText(composite, "");
		explanationText.setEditable(false);
		data = new FormData();
		data.width = 150;
		data.left = new FormAttachment(0, 85);
		data.right = new FormAttachment(100, -100);
		data.top = new FormAttachment(0, 0);
		explanationText.setLayoutData(data);

		CLabel explanationLabel = getWidgetFactory().createCLabel(composite, "Explanation:");
		data = new FormData();
		data.left = new FormAttachment(0, 0);
		data.right = new FormAttachment(explanationText, -ITabbedPropertyConstants.HSPACE);
		data.top = new FormAttachment(explanationText, 0, SWT.TOP);
		explanationLabel.setLayoutData(data);
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public void refresh() {
		if (explanationText!=null && !explanationText.isDisposed()){
			if (getElement() instanceof ExtensionPoint) {
				explanationText.setText(ExtensionPointUtil.getExplanation(((ExtensionPoint)getElement())));
			}
		}
	}
}